﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PolePosition.v3.Desktop.Selectors.Controls
{
    public partial class MeterProperties : DialogEditBase
    {
        public MeterProperties()
        {
            InitializeComponent();
            BindLists();
        }
        
        private void MeterProperties_Load(object sender, EventArgs e)
        {
            
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string SelectedMeterNotesList
        {
            get { return listSelectorNotes.GetSelectedValueList<int>(); }
            set
            {
                listSelectorNotes.SetSelectedValueList<int>(value);
                if (!listSelectorNotes.AllItemsChecked)
                    checkBoxXViewAll.Checked = false;
            }
        }

        private void BindLists()
        {
            if (Program.LookupTableData != null)
            {
                listSelectorNotes.DisplayMember = EntityLibrary.DistributionMeterNoteEnumerations.Columns.Name.ToString();
                listSelectorNotes.ValueMember = EntityLibrary.DistributionMeterNoteEnumerations.Columns.MeterNoteId.ToString();
                listSelectorNotes.DataSource = Program.LookupTableData.DistributionMeterNotes;
                listSelectorNotes.AddBlankOption<EntityLibrary.DistributionMeterNoteEntity>();

                SetListsEnabled();
            }
        }

        private void checkBoxXViewAll_CheckedChanged(object sender, EventArgs e)
        {
            SetListsEnabled();
        }

        private void SetListsEnabled()
        {
            bool _Enabled = !checkBoxXViewAll.Checked;

            foreach (Control _List in panelSelectors.Controls)
            {
                (_List as ListSelector).Enabled = _Enabled;
            }
        }
    }
}
